package com.APISecond.ArraysOrder;

import java.util.Arrays;
import java.util.Comparator;

public class OrderTest {
    public static void main(String[] args) {
        Student[]students=new Student[4];
        students[0]=new Student("蜘蛛精",169.5,23);
        students[1]=new Student("至尊宝",167.5,24);
        students[2]=new Student("紫霞",163.8,26);
        students[3]=new Student("紫霞",163.8,26);
//        Arrays.sort(students);
//        System.out.println(Arrays.toString(students));
//        Arrays.sort(students, new Comparator<Student>() {
//            @Override
//            public int compare(Student o1, Student o2) {
//                return Double.compare(o2.getHeight(),o1.getHeight());//降序
//            }
//        });
//        Arrays.sort(students, new Comparator<Student>() {
//            @Override
//            public int compare(Student o1, Student o2) {
//                return Double.compare(o2.getHeight(),o1.getHeight());//降序
//            }
//        });
        Arrays.sort(students,(o1,  o2)-> Double.compare(o2.getHeight(),o1.getHeight()));
        //静态方法的引用
        Arrays.sort(students,(o1,o2)->CompareByData_OrderTest.compareByAge(o1,o2));
        Arrays.sort(students,CompareByData_OrderTest::compareByAge);
        //实例方法引用//需要创建对象
        CompareByData_OrderTest compare=new CompareByData_OrderTest();
        Arrays.sort(students,(o1,o2)->compare.compareByAgeDesc(o1,o2));
        Arrays.sort(students,compare::compareByAgeDesc);
        System.out.println(Arrays.toString(students));

    }
}
